package com.brillilab.starter.controller.aio.inventory;

import com.brillilab.common.constant.ResultEnum;
import com.brillilab.common.entity.PageVo;
import com.brillilab.common.entity.ResponseVo;
import com.brillilab.common.exceptions.BrillilabException;
import com.brillilab.common.utils.MyBeanUtils;
import com.brillilab.domain.enums.inventory.InventoryRecordEnum;
import com.brillilab.domain.enums.lab.LabMemberPowerEnum;
import com.brillilab.domain.po.inventory.InventoryRecord;
import com.brillilab.domain.po.inventory.ReagentInventory;
import com.brillilab.domain.po.kit.Kit;
import com.brillilab.domain.po.kit.KitSpec;
import com.brillilab.domain.po.kit.ReagentType;
import com.brillilab.domain.po.lab.Lab;
import com.brillilab.domain.po.lab.LabMember;
import com.brillilab.domain.po.space.*;
import com.brillilab.domain.po.system.Dict;
import com.brillilab.domain.vo.inventory.*;
import com.brillilab.domain.vo.kit.KitDeleteList;
import com.brillilab.domain.vo.kit.SampleVo;
import com.brillilab.domain.vo.lab.LabMemberVo;
import com.brillilab.domain.vo.print.KitInventoryPrintVo;
import com.brillilab.domain.vo.space.BoxVo;
import com.brillilab.domain.vo.space.KitBoxVo;
import com.brillilab.domain.vo.user.UserInfoVo;
import com.brillilab.service.core.inventory.IInventoryRecordService;
import com.brillilab.service.core.inventory.IReagentInventoryService;
import com.brillilab.service.core.kit.IKitService;
import com.brillilab.service.core.kit.IKitSpecService;
import com.brillilab.service.core.kit.IReagentService;
import com.brillilab.service.core.kit.IReagentTypeService;
import com.brillilab.service.core.lab.ILabMemberService;
import com.brillilab.service.core.lab.ILabService;
import com.brillilab.service.core.space.*;
import com.brillilab.service.core.system.IDictService;
import com.brillilab.service.logic.inventory.InventoryDeleteLogic;
import com.brillilab.service.logic.inventory.ReagentInventoryLogic;
import com.brillilab.service.logic.user.UsersLogic;
import com.brillilab.starter.aspect.AspectLog;
import com.brillilab.starter.constant.StarterConstant;
import com.brillilab.starter.handler.RequestPower;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author wuzhiyu
 * @Title: inventory
 * @ProjectName brill_lab
 * @Description: TODO
 * @date 2018/11/139:26
 */
@Slf4j
@RestController
@RequestMapping("/api/inventoryManage")
public class InventoryController {
    @Autowired
    private IReagentInventoryService reagentInventoryService;
    @Autowired
    private UsersLogic usersLogic;
    @Autowired
    private IKitService kitService;
    @Autowired
    private IReagentService reagentService;
    @Autowired
    private ILabMemberService labMemberService;
    @Autowired
    private IKitSpecService kitSpecService;
    @Autowired
    private ReagentInventoryLogic reagentInventoryLogic;
    @Autowired
    private IDeviceService deviceService;
    @Autowired
    private IReagentTypeService reagentTypeService;
    @Autowired
    private IDictService dictService;
    @Autowired
    private IBoxService boxService;
    @Autowired
    private IKitBoxService kitBoxService;
    @Autowired
    private IPanelService panelService;
    @Autowired
    private ILabService labService;
    @Autowired
    private IRoomService roomService;
    @Autowired
    private IInventoryRecordService inventoryRecordService;
    @Autowired
    private InventoryDeleteLogic inventoryDeleteLogic;

    @AspectLog
    @PostMapping("/recommend")
    public ResponseVo recommend(@RequestBody ReagentSpaceGroup group, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(group, "data is null");
        if (CollectionUtils.isEmpty(group.getSingleList()) && CollectionUtils.isEmpty(group.getGroupList())) {
            throw new BrillilabException(ResultEnum.REQUEST_PARAM_LACK);
        }
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (group.getLabMemberId() != null) {
            LabMember mem = labMemberService.selectById(group.getLabMemberId());
            Assert.notNull(mem, "该实验室无此成员");
            if (!mem.getId().equals(info.getLabMemberId())) {
                throw new BrillilabException(ResultEnum.USER_NOT_POWER);
            }
        }
        List<List<ReagentPosition>> positionList = reagentInventoryLogic.getReagentPositionRecommand(group, info.getLabId(), info);
        return ResponseVo.success(positionList);
    }

    @GetMapping("/reagentInventoryList")
    public ResponseVo reagentInventoryList(Long kitId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(kitId, "kitId is null");
        Kit kit = kitService.selectById(kitId);
        Assert.notNull(kit, "kit not exist");
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!kit.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }

        List<KitInventory> voList = reagentInventoryLogic.getReagentInventoryList(kit, info);
        return ResponseVo.success(voList);
    }
    @GetMapping("/reagentInventoryDetailList")
    public ResponseVo reagentInventoryDetailList (Long kitId,Long groupId,@RequestHeader(value = StarterConstant.TOKEN) String token){
        Assert.notNull(kitId,ResultEnum.REQUEST_PARAM_LACK.getMessage());
        Assert.notNull(groupId,ResultEnum.REQUEST_PARAM_LACK.getMessage());
        UserInfoVo user = usersLogic.getUserByToken(token);
        return ResponseVo.success(reagentInventoryLogic.getReagentInventoryDetailList(kitId,groupId,user));
    }
    @GetMapping("/sampleInventoryList")
    public ResponseVo sampleInventoryList(Long sampleGroupId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.isTrue(sampleGroupId != null, "sampleGroupId is null");
        UserInfoVo info = usersLogic.getUserByToken(token);

        return ResponseVo.success(reagentInventoryLogic.sampleInventoryList(sampleGroupId, info));
    }
    
    @AspectLog
    @PostMapping("/inventoryIn")
    public ResponseVo inventoryIn(@RequestBody InventoryInVo inVo, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(inVo, "data is null");
        Assert.isTrue(!CollectionUtils.isEmpty(inVo.getPositionList()), "请先选择入库位置");
        UserInfoVo info = usersLogic.getUserByToken(token);
        reagentInventoryLogic.inventoryIn(inVo, info);
        return ResponseVo.success();
    }

    @GetMapping("/relateKitInfo")
    public ResponseVo relateKitInfo(Long inventoryId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(inventoryId, "inventoryId is null");
        ReagentInventory inventory = reagentInventoryService.selectById(inventoryId);
        Assert.notNull(inventory, "data is not exist");
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!inventory.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        RelateInventoryInfo inventoryInfo = reagentInventoryLogic.getRelateInventoryInfo(inventory);
        return ResponseVo.success(inventoryInfo);
    }

    @GetMapping("/panelInventoryCount")
    public ResponseVo panelInventoryCount(Long deviceId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(deviceId, "deviceId is null");
        Device device = deviceService.get(deviceId);
        Assert.notNull(device, "date is not exist");
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!device.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        List<PanelInventoryCount> list = deviceService.getPanelInventoryCount(device.getId());
        return ResponseVo.success(list);
    }

    @GetMapping("/reagentTypeInventory")
    public ResponseVo reagentTypeInventory(Long rootReagentTypeId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(rootReagentTypeId, "rootReagentTypeId is null");
        UserInfoVo info = usersLogic.getUserByToken(token);
        ReagentType type = reagentTypeService.selectById(rootReagentTypeId);
        Assert.notNull(type, "date is not exist");
        List<ReagentTypeInventoryCount> list = reagentTypeService.getTypeInventoryCount(info.getLabId(), type.getId());
        return ResponseVo.success(list);
    }
    
    @AspectLog
    @PostMapping("/boxMove")
    //@RequestPower(LabMemberPowerEnum.reagent)
    public ResponseVo boxMove(@RequestBody BoxMove boxMove, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(boxMove.getBoxId(), "box id is null");
        Assert.isTrue(boxMove.getPanelGridUsedList().size() > 0, "grid used is empty");
        Box box = boxService.get(boxMove.getBoxId());
        Assert.notNull(box, "box is not exist");
        Panel panel = panelService.get(box.getPanelId());
        Assert.notNull(panel, "panel is not exist");
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!box.getLabId().equals(info.getLabId()) || !(panel.getLabId().equals(info.getLabId()))||(!info.hasPower(LabMemberPowerEnum.Power.REAGENT)&&!(info.getLabMemberId().equals(box.getLabMemberId())))) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        BoxVo bv = reagentInventoryLogic.BoxMove(boxMove,info);
        return ResponseVo.success(bv);
    }
    
    @AspectLog
    @PostMapping("/kitBoxMoveToPanel")
    //@RequestPower(LabMemberPowerEnum.reagent)
    public ResponseVo kitBoxMoveToPanel(@RequestBody KitBoxMove kitBoxMove, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(kitBoxMove.getKitBoxId(), "box id is null");
        Assert.isTrue(kitBoxMove.getPanelGridUsedList().size() > 0, "grid used is empty");
        KitBox box = kitBoxService.get(kitBoxMove.getKitBoxId());
        Assert.notNull(box, "box is not exist");
        Panel panel = panelService.get(box.getPanelId());
        Assert.notNull(panel, "panel is not exist");
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!box.getLabId().equals(info.getLabId()) || !(panel.getLabId().equals(info.getLabId()))||(!info.hasPower(LabMemberPowerEnum.Power.REAGENT)&&!(info.getLabMemberId().equals(box.getLabMemberId())))) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        KitBoxVo bv = reagentInventoryLogic.kitBoxMoveToPanel(kitBoxMove,info);
        return ResponseVo.success(bv);
    }

    @AspectLog
    @PostMapping("/boxGridMoveToPanel")
    //@RequestPower(LabMemberPowerEnum.reagent)
    public ResponseVo boxGridMoveToPanel(@RequestBody BoxGridMoveToPanel toPanel, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(toPanel.getInventoryId(), "inventory id is null");
        Assert.isTrue(toPanel.getPanelGridUsedList().size() > 0, "panel grid is empty");
        UserInfoVo info = usersLogic.getUserByToken(token);
        ReagentInventory inventory = reagentInventoryService.selectById(toPanel.getInventoryId());
        Assert.notNull(inventory, "inventory not exist");
        if (!inventory.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        Panel panel = panelService.get(toPanel.getPanelGridUsedList().get(0).getPanelId());
        Assert.notNull(panel, "target panel not exist");
        if (!panel.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        if (inventory.getLabMemberId() == null && panel.getLabMemberId() != null) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        if (!inventory.getLabId().equals(info.getLabId()) || !(panel.getLabId().equals(info.getLabId()))||(!info.hasPower(LabMemberPowerEnum.Power.REAGENT)&&!(info.getLabMemberId().equals(inventory.getLabMemberId())))) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        KitBoxVo bv = reagentInventoryLogic.boxGridMoveToPanel(toPanel, panel, inventory,info);
        return ResponseVo.success(bv);
    }
    
    @AspectLog
    @GetMapping("/singleKitBoxMoveToBox")
    //@RequestPower(LabMemberPowerEnum.reagent)
    public ResponseVo singleKitBoxMoveToBox(Long kitBoxId, Long boxGridId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(kitBoxId, "kitBoxId is null");
        Assert.notNull(boxGridId, "boxGridId is null");
        KitBox kitBox = kitBoxService.get(kitBoxId);
        //ReagentInventory inventory = reagentInventoryService.selectById(inventoryId);
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!kitBox.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        Assert.notNull(kitBox, "kitBox not exist");
        BoxGrid boxGrid = boxService.getBoxGrid(boxGridId);
        if (!boxGrid.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        if (kitBox.getLabMemberId() == null && boxGrid.getLabMemberId() != null) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        if (!kitBox.getLabId().equals(info.getLabId())||(!info.hasPower(LabMemberPowerEnum.Power.REAGENT)&&!(info.getLabMemberId().equals(kitBox.getLabMemberId())))) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        BoxGridWithInvVo bv = reagentInventoryLogic.singleKitBoxMoveToBox(kitBox, boxGrid,info);
        return ResponseVo.success(bv);
    }

    @AspectLog
    @GetMapping("/gridToGrid")
    public ResponseVo gridToGrid(Long inventoryId, Long boxGridId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(inventoryId, "inventory id is null");
        Assert.notNull(boxGridId, "boxGridId is null");
        ReagentInventory inventory = reagentInventoryService.selectById(inventoryId);
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!inventory.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        Assert.notNull(inventory, "boxGrid not exist");
        BoxGrid boxGrid = boxService.getBoxGrid(boxGridId);
        if (!boxGrid.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        if (inventory.getLabMemberId() == null && boxGrid.getLabMemberId() != null) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        if (inventory.getLabMemberId() != null && boxGrid.getLabMemberId() != null) {
            if (!inventory.getLabMemberId().equals(boxGrid.getLabMemberId())) {
                throw new BrillilabException(ResultEnum.USER_NOT_POWER);
            }
        }
        BoxGridWithInvVo bv = reagentInventoryLogic.gridMoveToGrid(inventory, boxGrid,info);
        return ResponseVo.success(bv);
    }

    @AspectLog
    @PostMapping("/spaceInventory")
    public ResponseVo spaceInventory(@RequestBody SpaceInventoryPaged search, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(search.getSpaceId(), "reagent Id is null");
        Assert.notNull(search.getSpaceType(), "spaceType is null");
        UserInfoVo info = usersLogic.getUserByToken(token);
        switch (search.getSpaceType()) {
            case 0:
                Lab lab = labService.selectById(search.getSpaceId());
                Assert.notNull(lab, "Lab not exist");
                if (!lab.getId().equals(info.getLabId())) {
                    throw new BrillilabException(ResultEnum.USER_NOT_POWER);
                }
                break;
            case 1:
                Room room = roomService.get(search.getSpaceId());
                Assert.notNull(room, "room not exist");
                if (!room.getLabId().equals(info.getLabId())) {
                    throw new BrillilabException(ResultEnum.USER_NOT_POWER);
                }
                break;
            case 2:
                Device device = deviceService.get(search.getSpaceId());
                Assert.notNull(device, "device not exist");
                if (!device.getLabId().equals(info.getLabId())) {
                    throw new BrillilabException(ResultEnum.USER_NOT_POWER);
                }
                break;
            case 3:
                Panel panel = panelService.get(search.getSpaceId());
                Assert.notNull(panel, "panel not exist");
                if (!panel.getLabId().equals(info.getLabId())) {
                    throw new BrillilabException(ResultEnum.USER_NOT_POWER);
                }
                break;
            case 4:
                Box box = boxService.get(search.getSpaceId());
                Assert.notNull(box, "box not exist");
                if (!box.getLabId().equals(info.getLabId())) {
                    throw new BrillilabException(ResultEnum.USER_NOT_POWER);
                }
                break;
            default:
                throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        search.setCurrentLabMemberId(info.getLabMemberId());
        if (search.getPageSize() == 0 || search.getPageSize() >= 50) {
            search.setPageSize(50);
        }
        if (search.getPageNum() == 0) {
            search.setPageNum(1);
        }
        search.setCurrentLabMemberId(info.getLabMemberId());
        PageVo<ReagentInventoryWithOwner> pageInfo = reagentInventoryLogic.getSpaceInventoryVoPaged(info.getLabId(), search);
        return ResponseVo.success(pageInfo);
    }

    @GetMapping("/addInventoryRecord")
    public ResponseVo addInventoryRecord(Long kitId, Integer operateType, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        if (StringUtils.isBlank(token)) {
            throw new BrillilabException(ResultEnum.USER_NOT_LOGIN);
        }
        Assert.notNull(kitId, "kitId Id is null");
        Assert.notNull(operateType, "operateType is null");
        Kit kit = kitService.selectById(kitId);
        Assert.notNull(kit, "data not exist");
        UserInfoVo info = usersLogic.getUserByToken(token);
        if (!kit.getLabId().equals(info.getLabId())) {
            throw new BrillilabException(ResultEnum.USER_NOT_POWER);
        }
        InventoryRecord record = new InventoryRecord();
        record.setKitId(kitId);
        record.setUserName(info.getName());
        record.setUserId(info.getId());
        record.setLabId(info.getLabId());
        String opName = InventoryRecordEnum.getKey(operateType);
        Assert.isTrue(!org.springframework.util.StringUtils.isEmpty(opName), " operateType wrong");
        record.setOperate(operateType);
        record.setOperateName(opName);
        inventoryRecordService.insert(record);
        return ResponseVo.success();
    }

    @GetMapping("/boxInv")
    public ResponseVo boxWithGridInventory(Long boxId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        Assert.notNull(boxId, "boxId is null");
        UserInfoVo user = usersLogic.getUserByToken(token);
        BoxWithGridInvVo vo = reagentInventoryLogic.getBoxWithGridInventory(boxId, user);
        return ResponseVo.success(vo);
    }

    @GetMapping("/singleGirdBoxInv")
    public ResponseVo singleGirdBoxInv(Long boxId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        Assert.notNull(boxId, "boxId is null");
        UserInfoVo user = usersLogic.getUserByToken(token);
        SingleGridBoxVo vo = reagentInventoryLogic.getSingleGridBoxInvetenory(boxId, user);
        return ResponseVo.success(vo);
    }

    @GetMapping("/kitBoxInventoryInfo")
    public ResponseVo getkitBoxInventoryInfo(Long kitBoxId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        Assert.notNull(kitBoxId, "kitBoxId is null");
        UserInfoVo user = usersLogic.getUserByToken(token);
        InventoryInfo info = reagentInventoryLogic.getKitBoxInventoryInfo(kitBoxId,user);
        return ResponseVo.success(info);
    }

    @GetMapping("/oneInventoryInfo")
    public ResponseVo getBoxGridInventoryInfo(Long inventoryId, @RequestHeader(value = StarterConstant.TOKEN) String token) {
        Assert.notNull(inventoryId, "inventoryId is null");
        UserInfoVo user = usersLogic.getUserByToken(token);
        InventoryInfo info = reagentInventoryLogic.getBoxGridInventoryInfo( inventoryId, user);
        return ResponseVo.success(info);
    }

    @GetMapping("/getGroupId")
    public ResponseVo getGroupId() {
        Long id = reagentInventoryService.generateInventoryGroupId();
        return ResponseVo.success(id);
    }

    @GetMapping("/gridGroupId")
    public ResponseVo getGridGroupId(Long boxGridId,Long posCombId,@RequestHeader(value = StarterConstant.TOKEN) String token){
        Assert.notNull(boxGridId,"参数缺失");
        Assert.notNull(posCombId,"参数缺失");
        UserInfoVo user = usersLogic.getUserByToken(token);
        return ResponseVo.success(reagentInventoryLogic.getSingleGridBoxGroupInventoryInfo(boxGridId,posCombId,user));
    }

    @GetMapping("/inventoryDeleteList")
    public ResponseVo inventoryDeleteList(Long kitId,@RequestHeader(value = StarterConstant.TOKEN) String token){
        Assert.isTrue(kitId!=null && StringUtils.isNotBlank(token),"请求参数缺失！");
        UserInfoVo user = usersLogic.getUserByToken(token);
        List<KitDeleteList> kitDeleteLists=inventoryDeleteLogic.getKitInventoryDeleteList(kitId,user);
        return ResponseVo.success(kitDeleteLists);
    }
    
    @AspectLog
    @GetMapping("/inventoryDelete")
    @RequestPower(LabMemberPowerEnum.reagent)
    public ResponseVo inventoryDelete(Long kitId,@RequestHeader(value = StarterConstant.TOKEN) String token){
        Assert.isTrue(kitId!=null && StringUtils.isNotBlank(token),"请求参数缺失！");
        UserInfoVo userInfo = usersLogic.getUserByToken(token);
        KitInventoryPrintVo printVo=inventoryDeleteLogic.deleteKitInventory(kitId,userInfo);
        if(printVo!=null){
            return ResponseVo.success(printVo);
        }else{
            return ResponseVo.failure();
        }
    }

    @GetMapping("/deviceInvCount")
    public ResponseVo deviceInvCount(Long deviceGroupId,@RequestHeader(value = StarterConstant.TOKEN) String token){
            Assert.notNull(deviceGroupId,"请求参数缺失");
        UserInfoVo userInfo = usersLogic.getUserByToken(token);
           Integer count=  reagentInventoryLogic.getDeviceGroupInventoryCount(deviceGroupId,userInfo);
           return ResponseVo.successMap("count",count);
    }

    @AspectLog
    @RequestMapping(value="/delete/unlock",method=RequestMethod.POST)
    public ResponseVo deleteUnlock(@RequestBody List<Long> inventoryIds,@RequestHeader(value = StarterConstant.TOKEN) String token){

        Assert.isTrue(inventoryIds!=null && inventoryIds.size()>0 && StringUtils.isNotBlank(token),"请求参数缺失！");

        UserInfoVo userInfo=usersLogic.getUserByToken(token);

        reagentInventoryLogic.deleteUnlock(inventoryIds,userInfo);

        return ResponseVo.success();
    }

    @AspectLog
    @RequestMapping(value="/delete/confirm",method=RequestMethod.POST)
    public ResponseVo deleteConfirm(@RequestBody List<Long> inventoryIds,@RequestHeader(value = StarterConstant.TOKEN) String token){

        Assert.isTrue(inventoryIds!=null && inventoryIds.size()>0 && StringUtils.isNotBlank(token),"请求参数缺失！");

        UserInfoVo userInfo=usersLogic.getUserByToken(token);

        reagentInventoryLogic.deleteConfirm(inventoryIds,userInfo);

        return ResponseVo.success();
    }

    @GetMapping("/oneReagentKitInventory")
    public ResponseVo oneReagentKitInventory(Long kitId,@RequestHeader(value = StarterConstant.TOKEN) String token){
            Assert.notNull(kitId,ResultEnum.REQUEST_PARAM_LACK.getMessage());
            UserInfoVo user =usersLogic.getUserByToken(token);
            return ResponseVo.success(reagentInventoryLogic.getOneReagentKitInventory(kitId,user));
    }
    
	/**
	 * 是否有可用库存
	 * 
	 * @param kitId
	 * @return
	 */
	@RequestMapping(value = "/isUseInventory", method = RequestMethod.GET)
	public ResponseVo isUseInventory(@RequestHeader(name = StarterConstant.TOKEN) String token, @RequestParam Long kitId) {
		UserInfoVo user = usersLogic.getUserByToken(token);
		boolean inventory = reagentInventoryService.isUseInventory(user, kitId);
		return ResponseVo.successMap("isUseInventory", inventory ? 1 : 0);
	}
}
